package com.ljx.thread.thread05;

/**
 * @author LJX
 * @Description: TODO
 * @Date: 2022/11/1 17:03
 * @Version 1.0
 */
public class BThread extends Thread{
	private BrushAndBoard brushAndBoard;

	public BThread(BrushAndBoard brushAndBoard) {
		this.brushAndBoard = brushAndBoard;
	}

	@Override
	public void run() {
		/**
		 * 添加休眠可以使A线程获取画笔和画板，不会出现死锁问题
		 *try {
		 * 			Thread.sleep(1000);
		 *                } catch (InterruptedException e) {
		 * 			e.printStackTrace();
		 *        }
		 */

		synchronized (brushAndBoard.getBrush()){
			System.out.println("B线程获取画笔");
			synchronized (brushAndBoard.getBoard()){
				System.out.println("B线程获取画板");
			}
		}
	}
}
